#-*- coding:utf-8 -*-

import requests
#登陆的URL
loginUrl = 'https://iot.sundray.com.cn/iotp/web/WebHome/login'
postdata = {'userid':'*******',
            'passwd':'********'}
header = {
      'Host': 'iot.sundray.com.cn',
      'Connection': 'keep-alive',
      'Content-Length': '106',
      'Origin': 'https://iot.sundray.com.cn',
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      'Accept': 'application/json, text/javascript, */*; q=0.01',
      'X-Requested-With': 'XMLHttpRequest',
      'Referer': 'https://iot.sundray.com.cn/SPM/main.php',
      'Accept-Encoding': 'gzip, deflate, br',
      'Accept-Language': 'zh-CN,zh;q=0.8'
}
s = requests.Session()
r1 = s.post(loginUrl,data=postdata,headers=header)
print(r1.text)
data={
    "opr":"addgroup",
    "msg":'{"parentGroupID":1,"groupName":"102","groupDesc":"102"}'
    }
groupurl="https://iot.sundray.com.cn/iotp/web/v2/DevicesManagement"
print("------------1--------")
#s.headers.update(header)
r1 = s.post(groupurl,data=data,headers=header)
print(r1)
print("---------------2-------")
print(r1.text)
